<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <title>Credit Profiles</title>
    </h:head>
    <h:body>
        <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
            <f:view beforePhase="#{CreditProfileManagedBean.initView}">

                <h:form id="formMain">
                    <p:growl id="notif" showDetail="true"/>  
                    <p:poll interval="5"   
                            actionListener="#{MessageManagedBean.checkNewMessage}" immediate="true" update="notif" />
                    <!-- IDLE DIALOG for -->
                    <p:confirmDialog message="You have been idle for too long. Do you want to continue?"  
                                     showEffect="bounce" hideEffect="explode"  
                                     header="Warning message" severity="alert" widgetVar="confirmation">  
                        <p:commandButton value="Yes" onclick="confirmation.hide()" type="button" /> 
                        <p:commandButton value="No" update="panel" oncomplete="confirmation.hide()"  
                                         actionListener="#{UserManagedBean.doLogout}" />  

                    </p:confirmDialog>

                    <p:idleMonitor timeout="300000" onidle="confirmation.show()" />  
                    <!--END OF IDLE DIALOG-->

                    <div id="header">
                        <h:graphicImage value="../image/newHeader.jpg"/>
                    </div>
                    <div id="content">
                        <table>

                            <tr>    
                                <td style="vertical-align:top">
                                    <p:toolbar style="font-size:80%;height:33px;width:207px"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome="FinanceDeptWorkspace"/>
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>
                                            <p:button title="Mail" outcome="messages" image="ui-icon-mail-closed"/>     
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar>

                                    <p:menu id="menu" style=" width:205px;height: 610px;font-family: Tahoma;border-style: double;font-size: 80%">  
                                        <p:submenu label="Finance Menu">  
                                            <p:menuitem value="Finance Dept Home" url="http://localhost:8080/MerlionERP-war/FRM/FinanceDeptWorkspace.xhtml" ajax="false" icon="ui-icon ui-icon-home"/>  
                                        </p:submenu>
                                        <p:submenu label=" Credit Profiles">
                                            <p:menuitem value="Add New Credit Profile" url="http://localhost:8080/MerlionERP-war/FRM/addCreditProfile.xhtml" ajax="false" icon="ui-icon ui-icon-document"/>  
                                            <p:menuitem value="View Credit Profiles" url="http://localhost:8080/MerlionERP-war/FRM/viewCreditProfile.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="Perform Credit Check" url="http://localhost:8080/MerlionERP-war/FRM/CreditCheck.xhtml" ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label=" Invoices">
                                            <p:menuitem value="Add New Invoice" url="http://localhost:8080/MerlionERP-war/FRM/addInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-document" />
                                            <p:menuitem value="View All Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View Outstanding Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewOutstandingInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                            <p:menuitem value="View Overdue Invoices" url="http://localhost:8080/MerlionERP-war/FRM/viewOverdueInvoice.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />
                                        </p:submenu>
                                        <p:submenu label="Refund">
                                            <p:menuitem value="View Pending Refunds" url="http://localhost:8080/MerlionERP-war/FRM/ViewRefundEntity.xhtml"   ajax="false" icon="ui-icon ui-icon-document" />
                                        </p:submenu>
                                        <p:submenu label="Payment">
                                            <p:menuitem value="Perform Customer Payment" url="http://localhost:8080/MerlionERP-war/FRM/PerformPayment.xhtml"   ajax="false" icon="ui-icon ui-icon-cart" />
                                            <p:menuitem value="View Payment History" url="http://localhost:8080/MerlionERP-war/FRM/ViewCustomerPaymentJournal.xhtml"   ajax="false" icon="ui-icon ui-icon-search" />

                                        </p:submenu>
                                    </p:menu>

                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style="vertical-align:top">
                                    <h:graphicImage value="creditReport.jpg" style="width:55px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Credit Profiles" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>

                                    <p:toolbar style="background-color:  #d9bb73;font-size: 70%;width:1127px"> 

                                        <!-- <p:toolbarGroup align="left" style="text-indent: 500px;font-size: 30px">  
                                             CREDIT PROFILES
                                         </p:toolbarGroup> -->
                                        <p:divider />
                                        <p:toolbarGroup align="left">  
                                            <!--  <p:commandButton type="push" title="Save" image="ui-icon-disk"/>  -->
                                            <p:commandButton type="push" title="Delete" value="Delete" image="ui-icon-trash" onclick="deleteDialog.show()"/>                                        
                                            <p:commandButton value="Credit Profile Report" image="ui-icon-print" ajax="false" immediate="true" actionListener="#{jasperManagedBean.generateCreditProfileReport}" />
                                            <p:divider />  
                                            <p:button value="New Credit Profile" outcome="addCreditProfile" image="ui-icon-plus" />
                                            <p:button value="Validate Credit Profile" outcome="validateCreditProfile" image="ui-icon-notice" />
                                        

                                        </p:toolbarGroup>  

                                    </p:toolbar> 



                                    <p:dataTable  height="650" id="display" 
                                                  var="creditProfiles" value="#{CreditProfileManagedBean.selectedCreditProfiles}"                       
                                                  paginator="true" rows="5"
                                                  paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                  rowsPerPageTemplate="5,10,15"  style="font-size:70%;width:1132px;"
                                                  rowEditListener="#{CreditProfileManagedBean.onEditRow}"
                                                  selection="#{CreditProfileManagedBean.selectedCreditProfiless}" 
                                                  emptyMessage="No data found with given criteria" widgetVar="creditProfileTable">  



                                        <f:facet name="header">
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:" style="margin-left:740px" />  
                                                <p:inputText id="globalFilter" onkeyup="creditProfileTable.filter()" style="right:-100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet>

                                        <p:column style="width: 16px" selectionMode="multiple" />  

                                        <p:column style="width:20px; border-left-color:transparent;border-right-color:transparent">
                                            <f:facet name="header">
                                                <h:outputText value="View"/>
                                            </f:facet>
                                            <!--VIEW DETAILS-->
                                            <p:rowToggler />
                                        </p:column>
                                        <!--EDIT-->   
                                        <p:column style="width:10px; border-left-color:transparent;border-right-color:transparent">
                                            <f:facet name="header">
                                                <h:outputText value="Edit"/>
                                            </f:facet>
                                            <p:rowEditor />
                                        </p:column>
                                        <!--DELETE-->
                                        <p:column style="width:20px;border-left-color:transparent;">
                                            <f:facet name="header">
                                                <h:outputText value="Del."/>
                                            </f:facet>
                                            <p:commandButton title="Delete" image="ui-icon ui-icon-trash" ajax="true" immediate="true"
                                                             update="display" oncomplete="customerdialog.show()">
                                                <f:setPropertyActionListener target="#{CreditProfileManagedBean.selectedCreditProfile}"
                                                                             value="#{creditProfiles}"/>
                                            </p:commandButton>
                                        </p:column>

                                        <p:column style="width: 100px" sortBy="#{creditProfiles.creditProfileId}" filterBy="#{creditProfiles.creditProfileId}" filterMatchMode="contains">
                                            <f:facet name="header">
                                                <h:outputText value="Credit Profile ID"/> 
                                            </f:facet>
                                            <h:outputText value="#{creditProfiles.creditProfileId}"/>
                                        </p:column>

                                        <p:column style="width: 100px" sortBy="#{creditProfiles.customerId}" filterBy="#{creditProfiles.customerId}" filterMatchMode="contains">  

                                            <f:facet name="header">  
                                                <h:outputText value="Customer Id" />  
                                            </f:facet>  
                                            <h:outputText value="#{creditProfiles.customerId}" />  

                                        </p:column>   

                                        <p:column style="width: 100px" headerText="Customer Grade" sortBy="#{creditProfiles.customerGrade}" filterBy="#{creditProfiles.customerGrade}" filterMatchMode="contains">  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{creditProfiles.customerGrade}" />  
                                                </f:facet>  
                                                <f:facet name="input">  
                                                    <h:selectOneMenu value="#{creditProfiles.customerGrade}">
                                                        <f:selectItem itemLabel="A" itemValue="A" />
                                                        <f:selectItem itemLabel="B" itemValue="B"/>
                                                        <f:selectItem itemLabel="C" itemValue="C"/>
                                                    </h:selectOneMenu>
                                                </f:facet>  
                                            </p:cellEditor>
                                        </p:column>  

                                        <p:column style="width: 100px" headerText="Credit Limit" sortBy="#{creditProfiles.creditLimit}" filterBy="#{creditProfiles.creditLimit}" filterMatchMode="contains">  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{creditProfiles.creditLimit}" >
                                                        <f:convertNumber type="currency" currencySymbol="S$"/>
                                                    </h:outputText>
                                                </f:facet>  
                                                <f:facet name="input">  
                                                    <h:inputText value="#{creditProfiles.creditLimit}" />  
                                                </f:facet>  

                                            </p:cellEditor>
                                        </p:column>  

                                        <p:column style="width: 100px" headerText="Payment Method" sortBy="#{creditProfiles.methodOfPayment}" filterBy="#{creditProfiles.methodOfPayment}" filterMatchMode="contains">
                                            <p:cellEditor>
                                                <f:facet name="output">
                                                    <h:outputText value="#{creditProfiles.methodOfPayment}"/>
                                                </f:facet>
                                                <f:facet name="input">
                                                    <h:selectManyCheckbox style=" outline-style: none; border-style: none;" value="#{creditProfiles.methodOfPayment}" > 
                                                        <f:selectItem itemLabel="Banking-GIRO" itemValue="Banking" />
                                                        <f:selectItem itemLabel="Cash" itemValue="Cash" />
                                                        <f:selectItem itemLabel="Credit Card" itemValue="Credit Card" />
                                                    </h:selectManyCheckbox>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>

                                        <p:column style="width: 100px" headerText="Status" sortBy="#{creditProfiles.creditProfileStatus}" filterBy="#{creditProfiles.creditProfileStatus}" filterMatchMode="contains">
                                            <p:cellEditor>
                                                <f:facet name="output">
                                                    <h:outputText value="#{creditProfiles.creditProfileStatus}"/>
                                                </f:facet>
                                                <f:facet name="input">
                                                    <h:selectOneMenu value="#{creditProfiles.creditProfileStatus}">
                                                        <f:selectItem itemLabel="Freeze" itemValue="Frozen" />
                                                        <f:selectItem itemLabel="Valid" itemValue="Valid"/>
                                                    </h:selectOneMenu>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>

                                        <p:column style="width:40px">  
                                            <f:facet name="header">
                                                <h:outputText value="Details"  />
                                            </f:facet>
                                            <p:commandLink update="formMain:display1" oncomplete="editDialog.show()" title="Edit Details">
                                                <p:graphicImage value="about_icon.png" style="width:20px;height:20px"/>
                                                <f:setPropertyActionListener value="#{creditProfiles}" target="#{CreditProfileManagedBean.selectedViewCreditProfile}" />  
                                                <f:setPropertyActionListener value="#{true}" target="#{CreditProfileManagedBean.editMode}" />  
                                            </p:commandLink>                                                                
                                        </p:column> 


                                        <p:rowExpansion>  
                                            <h:panelGrid  id="expansionRow" columns="4" 
                                                          style="border-color:transparent;column-rule-style:hidden">

                                                <h:outputText value="Credit Profiles ID :" style="font-weight: bolder"/>  
                                                <h:outputText value="#{creditProfiles.creditProfileId}" />  

                                                <h:outputText value="Customer ID        :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.customerId}"/>  

                                                <h:outputText value="Customer Grade     :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.customerGrade}" />  

                                                <h:outputText value="Payment Defaults   :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.defaults}" /> 

                                                <h:outputText value="Balance Payable    :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.balancePayable}" />  

                                                <h:outputText value="Credit Balance     :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.creditBalance}" />  

                                                <h:outputText value="Cash In Advance    :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.paymentAsCIA}" /> 

                                                <h:outputText value="Credit Limit       :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.creditLimit}" />  

                                                <h:outputText value="Method of Payment  :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.methodOfPayment}" />  

                                                <h:outputText value="Bank Name          :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.bankName}" />  

                                                <h:outputText value="Account Number     :" style="font-weight: bolder"/> 
                                                <h:outputText value="#{creditProfiles.accountNumber}" />  

                                                <h:outputText value="Credit Card Type   :" style="font-weight: bolder"/> 
                                                <h:outputText value="#{creditProfiles.creditCardType}" />  

                                                <h:outputText value="Credit Card Number :" style="font-weight: bolder"/> 
                                                <h:outputText value="#{creditProfiles.creditCardNumber}" />  

                                                <h:outputText value="Account Status     :" style="font-weight: bolder"/>
                                                <h:outputText value="#{creditProfiles.creditProfileStatus}" /> 

                                            </h:panelGrid>  
                                        </p:rowExpansion>  

                                    </p:dataTable>  


                                    <!--DIALOG FOR DELETING A  SINGLE ROW-->
                                    <p:confirmDialog message="Are you sure you want to delete this credit profile?"  
                                                     showEffect="blind" hideEffect="explode"  
                                                     header="Delete Credit Profile" severity="alert" widgetVar="customerdialog">  
                                        <p:commandButton value="Yes" update="formMain:msgs panel" ajax="true" immediate="true" oncomplete="customerdialog.hide()"  
                                                         actionListener="#{CreditProfileManagedBean.doDelete}" />  
                                        <p:commandButton value="No" onclick="customerdialog.hide()" type="button" />   
                                    </p:confirmDialog>

                                    <!--DIALOG FOR DELETING MULTIPLE ROW-->
                                    <p:dialog header="Delete Selected Records" modal="true" widgetVar="deleteDialog">

                                        <h:outputText value="You are about to permanently delete records." /><br /><br />
                                        <h:outputText value="Are you sure you want to continue?" /><br /><br/>

                                        <center>
                                            <p:commandButton value="Yes" ajax="true" immediate="true" update="msgs panel" oncomplete="deleteDialog.hide()" actionListener="#{CreditProfileManagedBean.doDeletes}" />
                                            <p:commandButton value="No" onclick="deleteDialog.hide()" /> 

                                        </center>
                                    </p:dialog>

                                    <!--DIALOG FOR CUSTOMER DATA-->
                                    <p:dialog header="Company Name" widgetVar="customer" resizable="false"  
                                              width="300" showEffect="fold" hideEffect="explode">

                                        <h:outputText value="Company Name" />  
                                        <h:outputText value=":" /> 
                                        <h:outputText style="font-size: 12px" id="company" value=" #{CreditProfileManagedBean.customerName}" />  

                                    </p:dialog>

                                    <!--DIALOG FOR VIEW-->
                                    <p:dialog header="Credit Profile Details" widgetVar="editDialog" resizable="false"  
                                              width="800" showEffect="explode" hideEffect="explode">  
                                        <center> 
                                            <h:panelGrid id="display1" columns="3" cellpadding="4">  

                                                <h:outputText value="Credit Profile ID:" />                                                 
                                                <h:outputText value=" #{CreditProfileManagedBean.selectedViewCreditProfile.creditProfileId}" /> 
                                                <h:outputText value=""/>
                                                
                                                
                                                <h:outputText value="Customer ID:" />                                                 
                                                <h:outputText value=" #{CreditProfileManagedBean.selectedViewCreditProfile.customerId}" /> 
                                                
                                                <p:commandButton style="font-size:10px" immediate="true" update="company" ajax="true" value="Get Company Name" actionListener="#{CreditProfileManagedBean.getCompanyNames}" onclick="customer.show()"/>  

                                                <h:outputText value="Cash In Advance(S$):" />  
                                                <p:inputText value="#{CreditProfileManagedBean.selectedViewCreditProfile.paymentAsCIA}" rendered="#{CreditProfileManagedBean.editMode}" required="true" label="Payment As Cash In Advance"/>
                                                <h:outputText value=""/>
                                                
                                                <h:outputText value="Bank Name:" />
                                                <p:inputText value="#{CreditProfileManagedBean.selectedViewCreditProfile.bankName}" rendered="#{CreditProfileManagedBean.editMode}" required="true" label="Account Number"/>
                                                <h:outputText value=""/>
                                                
                                                <h:outputText value="Account Number:" />
                                                <p:inputText value="#{CreditProfileManagedBean.selectedViewCreditProfile.accountNumber}" rendered="#{CreditProfileManagedBean.editMode}" required="true" label="Bank Name"/>
                                                <h:outputText value=""/>
                                                
                                                <h:outputText value="Credit Card Type:" />
                                                <h:panelGroup>
                                                    <h:outputText value="#{CreditProfileManagedBean.selectedViewCreditProfile.creditCardType}" rendered="#{!CreditProfileManagedBean.editMode}"/>
                                                    <h:selectOneMenu value="#{CreditProfileManagedBean.selectedViewCreditProfile.creditCardType}" rendered="#{CreditProfileManagedBean.editMode}" required="true" label="Credit Card Type">  
                                                        <f:selectItem itemLabel="Visa" itemValue="Visa" />  
                                                        <f:selectItem itemLabel="Master Card" itemValue="Master Card"/>   
                                                        <f:selectItem itemLabel="American Express(Amex)" itemValue="Amex"/>
                                                    </h:selectOneMenu>  
                                                </h:panelGroup>
                                                <h:outputText value=""/>

                                                <h:outputText value="Credit Card Number:" />
                                                <p:inputMask mask="9999999999999999" value="#{CreditProfileManagedBean.selectedViewCreditProfile.creditCardNumber}" rendered="#{CreditProfileManagedBean.editMode}" required="true" label="Credit Card Number"/>
                                                <h:outputText value=""/>
                                                
                                                <h:outputText value="" />
                                                <h:outputText value=""/>
                                                <h:outputText value=""/>

                                                <center>
                                                    <p:outputPanel rendered="#{CreditProfileManagedBean.editMode}" layout="block" style="text-align:right">  
                                                        <p:commandButton value="Save" ajax="false" update="formMain:panel" immediate="false" actionListener="#{CreditProfileManagedBean.onEditDialog}"   
                                                                         image="ui-icon ui-icon-disk" />  
                                                        <p:commandButton value="Cancel" onclick="editDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  
                                                    </p:outputPanel>
                                                </center>
                                                
                                            </h:panelGrid> 
                                        </center>
                                    </p:dialog> 
                                </td>
                            </tr>
                        </table>
                    </div>
                    
                    <div id="footer">
                        <h:graphicImage value="../image/merlionfooter.jpg"/>
                    </div>
                </h:form>
            </f:view>
        </f:view>
    </h:body>
</html>

